local sk__liegong = fk.CreateSkill {

  name = "sk__liegong",

  tags = {  },

}



sk__liegong:addEffect("viewas", {
  name = "sk__liegong",
  anim_type = "offensive",
  pattern = "slash|.|.|.|fire__slash",
  prompt = "#sk__liegong",
  card_filter = function(self, player, to_select, selected)
    if Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand then
      if #selected == 0 then
        return true
      else
        return table.every(selected, function(id) return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit end)
      end
    end
  end,
  view_as = function(self, player,cards)
    if #cards == 0 then return end
    local c = Fk:cloneCard("fire__slash")
    c.skillName = sk__liegong.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local n = #use.card.subcards
    if n >= 1 then
      use.unoffsetableList = player.room.alive_players
    end
    if n >= 3 then
      use.additionalDamage = (use.additionalDamage or 0) + 1
    end
  end,
  after_use = function(self, player, use)
    local n = #use.card.subcards
    if n >= 2 and not player.dead then
      player:drawCards(3, sk__liegong.name)
    end
    if n >= 4 then
      local room = player.room
      for _, id in ipairs(use.tos) do
        local to = id
        if use.damageDealt[id] and not to.dead then
          local skills = table.map(table.filter(to.player_skills, function(s)
            return s:isPlayerSkill(to) and s.visible
          end), function(s)
            return s.name
          end)
          if #skills > 0 then
            room:handleAddLoseSkills(to, "-"..table.random(skills), nil, true, false)
          end
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:isWounded() and player:usedSkillTimes(sk__liegong.name, Player.HistoryTurn) < 2 or
      player:usedSkillTimes(sk__liegong.name, Player.HistoryTurn) < 1
  end,
  enabled_at_response = function(self, player, response)
    return not response and (player:isWounded() and player:usedSkillTimes(sk__liegong.name, Player.HistoryTurn) < 2 or
      player:usedSkillTimes(sk__liegong.name, Player.HistoryTurn) < 1)
  end,
})

sk__liegong:addEffect("targetmod", {
  name = "#sk__liegong_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and #card.skillNames>0 and table.contains(card.skillNames, "sk__liegong")
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return card and #card.skillNames>0 and table.contains(card.skillNames, "sk__liegong")
  end,
})

return sk__liegong